package com.qf.servlet;

import com.qf.constant.MessageConstant;
import com.qf.pojo.PageBean;
import com.qf.pojo.User;
import com.qf.service.UserService;
import com.qf.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author AzureSky_X
 * @Date 2021/1/15 8:55
 * @Version 1.0
 */
@WebServlet("/user/page")
public class UserPageController extends HttpServlet {
    private UserService userService=new UserServiceImpl();
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String errorMessage="";
        try {
            //获取页码
            String pageNo=request.getParameter("pageNo");


            //返回分页对象，因为页面需要这些数据
            PageBean<User> pageBean=userService.selectPage(pageNo,5);
            request.getRequestDispatcher("user-page.jsp").forward(request,response);
            return;
        } catch (RuntimeException e) {
        errorMessage = MessageConstant.DB_ERROR;
    } catch (Exception e) {
        errorMessage = MessageConstant.COMMON_ERROR;
    }
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}